package org.xlx.xlx_oa.role_user.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.xlx.xlx_oa.common.PageVo;
import org.xlx.xlx_oa.common.ResponseBean;
import org.xlx.xlx_oa.role_user.api.SysNotificationApi;
import org.xlx.xlx_oa.role_user.domain.dto.SysNotificationDto;
import org.xlx.xlx_oa.role_user.service.SysNotificationService;

import java.util.List;

@RestController
@RequestMapping("/v1/sys-notification")
public class SysNotificationController implements SysNotificationApi {
    @Autowired
    private SysNotificationService sysNotificationService;

    @PostMapping("/uploadImage")
    @Override
    public ResponseBean<String> uploadFile(@RequestPart("file") MultipartFile file) {
        try {
            return ResponseBean.successFactory(sysNotificationService.upload(file));
        } catch (Exception e) {
            return ResponseBean.failureFactory(e.getMessage());
        }
    }

    @PostMapping("/notifications")
    @Override
    public ResponseBean<List<SysNotificationDto>> getPageNotifications(@RequestBody PageVo pageVo) {
        List<SysNotificationDto> dtos = sysNotificationService.selectNotificationsByUserId(pageVo);
        return ResponseBean.successFactory(dtos);
    }

    @PostMapping("/count")
    @Override
    public ResponseBean getCount() {
        Integer count = sysNotificationService.getCount();
        return ResponseBean.successFactory(count);
    }
}

